#region Imports
using System;
using System.Data;
using System.Data.SqlClient;

using BO = PHSRAG.Insight21.BusinessObjects;
using DataAccess = PHSRAG.Utility.DataAccess;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.CDS
{
	/// <summary>
	/// Represents a certification a person has received for training
	/// </summary>
	public class Certification : BO.SaveableBusinessObject
	{
		private const string CacheKey = "Certification_B084814C-E130-4358-A477-FEED9B21A8A8";

		private DataRow row;

		/// <summary>
		/// Type of the certification (e.g. IRB, IACUC)
		/// </summary>
		public string Type
		{
			get{ return (string)row["Type"]; }
		}

		/// <summary>
		/// Subtype of certification (e.g. PHS, CITI C.E.)
		/// </summary>
		public string SubType
		{
			get
			{
				object o = row["SubType"];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Date the person was certified (null if date not available in the data repository)
		/// </summary>
		public DateTime Date
		{
			get
			{
				object o = row["Date"];
				return (o == DBNull.Value) ? DateTime.MinValue : (DateTime)o;
			}
		}
		
		/// <summary>
		/// The person's status of the certification
		/// </summary>
		public string Status
		{
			get
			{
				object o = row["Status"];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Initializes the base class with the specified caching policy and sets the internal row reference
		/// to the one passed in
		/// </summary>
		/// <param name="cachePolicy">policy to use to cache this instance</param>
		public Certification(ICachePolicy cachePolicy, DataRow row) : base(cachePolicy)
		{
			this.row = row;
		}

		/// <summary>
		/// Puts this instance in the cache
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(CacheKey, this);
		}

		/// <summary>
		/// Removes this instance from the cache
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(CacheKey);
		}

		/// <summary>
		/// Not meant to be loaded using this method; use constructor and pass in a dataRow with data
		/// </summary>
		/// <param name="connectionString"></param>
		/// <param name="args"></param>
		public override void Load(string connectionString, params object[] args)
		{
			throw new Exception("Certification not meant to be loaded this way, use constructor and pass in a dataRow");
		}

		/// <summary>
		/// Not yet implemented
		/// </summary>
		/// <param name="connectionString"></param>
		/// <param name="args"></param>
		public override void Save(string connectionString, params object[] args)
		{
			throw new Exception("Save on Certification not supported");
		}

	}
}
